package com.itheima;

public class TestLambda {
    public static void main(String[] args) {

        testD();
    }
    //创建A接口的匿名内部类
    public static void  testA(){
        A a1 = new A() {
            @Override
            public void show(String name, int age) {
                System.out.println(name +","+age);
            }
        };

    A a2 = (name, age) -> System.out.println(name +","+age);
    a2.show("张三", 18);

    A a3 = TestLambda::show2;
     a3.show("李四", 19);

     TestLambda testLambda = new TestLambda();
     A a4 = testLambda::show3;
     a4.show("王五", 20);

    }

    public static void show2(String name, int age){
        System.out.println("show2:"+name+","+age);
    }
    public void show3(String name, int age){
        System.out.println("show3:"+name+","+age);

    }

    public static void testB(){
        //创建B接口的匿名内部类
        B b = new B() {
            @Override
            public void show(String name) {
                System.out.println(name );
            }
        };

        //创建B接口的Lambda表达式
        B b2 = (name) -> System.out.println(name);

        //创建B接口的方法引用
        B b3 = System.out::println;
        b3.show("张三");
    }

    public static void testC(){
        //创建C接口的匿名内部类
        C c = new C() {
            @Override
            public String show(String name) {
                return "name="+name;
            }
        };

        C c2 = (String name) ->  "name="+name;

        C c3 = TestLambda::show4;

        String result = c3.show("王五");
        System.out.println(result);

    }

    public static String show4(String name){
        return "name = " + name;
    }

    public static void testD(){
        D d1 = new D() {
            @Override
            public int max(int a, int b) {
                return a>b?a:b;
            }
        };

        D d2 =(a, b) ->a>b?a:b;
        int  max = d2.max(1, 2);
        System.out.println(max);

        System.out.println("------------------------------------------------");
        D d3 = Math::max;
        int max2 = d3.max(10, 20);
        System.out.println(max2);

    }
}
